package auxiliares;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

public class Server {
    
    public static String getContentOfURL( String path ){
        try {
            
            URL           url      = new URL(path);
            URLConnection url_conn = url.openConnection();
            
            InputStreamReader in_reader   = new InputStreamReader(url_conn.getInputStream());
            BufferedReader    buff_reader = new BufferedReader   (in_reader);
            
            String input = buff_reader.readLine();
            
            buff_reader.close();
            in_reader  .close();
            
            return input;
            
        } catch (MalformedURLException ex) {
            return "";
        } catch (IOException e){
            return "";
        }
    }
    
    public static BufferedImage getImageOfURL( String path ){
        try {
            
            URL           url        = new URL(path);
            BufferedImage buff_image = ImageIO.read( url );

            return buff_image;
            
        } catch (MalformedURLException ex) {
            return null;
        } catch (IOException e){
            return null;
        }
    }
    
}
